package buyers;

import cart.ShoppingCart;
import goods.Goods;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

public class Buyer {
    private String userName;
    private String passWord;
    private ArrayList<ShoppingCart> shoppingCartArrayList = new ArrayList<>();
    private ArrayList<Long> orderArrayList = new ArrayList<>();

    public Buyer(String userName, String passWord,String order, String shoppingCart) {
        this.userName = userName;
        this.passWord = passWord;
        String[] tempOrder = order.split("、");
        String[] tempShoppingCartData = shoppingCart.split("//");
        for (String t:tempOrder) {
            orderArrayList.add(Long.valueOf(t));
        }
        for (String t:tempShoppingCartData) {
            String[] temp = t.split("，");
            ShoppingCart tempShoppingCart = new ShoppingCart(temp[0],temp[1],temp[2],temp[3]);
            shoppingCartArrayList.add(tempShoppingCart);

        }
    }


    public String getUserName() {
        return userName;
    }


    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public ArrayList<ShoppingCart> getShoppingCartArrayList() {
        return shoppingCartArrayList;
    }

    public void setShoppingCartArrayList(ArrayList<ShoppingCart> shoppingCartArrayList) {
        this.shoppingCartArrayList = shoppingCartArrayList;
    }

    public ArrayList<Long> getOrderArrayList() {
        return orderArrayList;
    }

    public void setOrderArrayList(ArrayList<Long> orderArrayList) {
        this.orderArrayList = orderArrayList;
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append(userName);
        str.append(" ");
        str.append(passWord);
        str.append(" ");
        for(int i = 0 ; i < orderArrayList.size() ; i ++ ){
            if(i == 0) {
                str.append(orderArrayList.get(i));
            }else
                str.append("、"+orderArrayList.get(i));
        }
        str.append(" ");
        for(int i = 0 ; i < shoppingCartArrayList.size() ; i ++ ) {
            ShoppingCart SC = shoppingCartArrayList.get(i);
            if(i == 0) {
                str.append(SC.getName()+"，"+SC.getPrice()+"，");
                int j = 0;
                str.append(SC.getAmount()+"，"+SC.getId());
            }else {
                str.append("//");
                str.append(SC.getName()+"，"+SC.getPrice()+"，");
                int j = 0;
                str.append(SC.getAmount()+"，"+SC.getId());
            }
        }
        str.append("\n");
        String S = new String(str);
        return S;
    }
}
